package member.action;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import member.dao.MemberDAO;
import member.model.MemberInfo;
import board.action.PagingAction;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.Preparable;
import com.opensymphony.xwork2.ModelDriven;

public class ListAction implements Action,Preparable,ModelDriven{
	MemberDAO memberDAO;
	MemberInfo memberInfo;
	private List<MemberInfo> list = new ArrayList<MemberInfo>();
	
	private int currentPage = 1;
	private int totalCount;
	private int blockCount = 10;
	private int blockPage = 5;
	private String pagingHtml;
	private PagingAction page;
	private String code; 
	
	
	public ListAction(){
		memberDAO = MemberDAO.getInstance();
	}
	
	public String execute() throws Exception {
	//	totalCount = memberDAO.selectCnt();
		PagingAction paging = new PagingAction(currentPage, totalCount, blockCount, blockPage, code);
		pagingHtml = paging.getPagingHtml().toString();
		
		Map map = new HashMap();
		map.put("start", paging.getStartCount());
		map.put("end", paging.getEndCount());
		
		list = memberDAO.select(map);
		
		return SUCCESS;
	}
	
	
	
	public int getCurrentPage() {
		return currentPage;
	}
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}
	public int getBlockCount() {
		return blockCount;
	}
	public void setBlockCount(int blockCount) {
		this.blockCount = blockCount;
	}
	public int getBlockPage() {
		return blockPage;
	}
	
	public List<MemberInfo> getList() {
		return list;
	}

	public void setList(List<MemberInfo> list) {
		this.list = list;
	}

	public String getPagingHtml() {
		return pagingHtml;
	}

	public void setPagingHtml(String pagingHtml) {
		this.pagingHtml = pagingHtml;
	}

	public void setBlockPage(int blockPage) {
		this.blockPage = blockPage;
	}

	public void prepare() throws Exception {
		memberInfo = new MemberInfo();
		
	}
	public Object getModel() {
		return memberInfo;
	}
}
